<template>
  <el-row>
    <el-col :span="8" :offset="8">
      <el-form :inline="false" class="demo-form-inline">
        <el-form-item label="姓名">
          <el-input v-model="stu.name" placeholder="请填写姓名"></el-input>
        </el-form-item>
        <el-form-item label="分数">
          <el-input v-model="stu.score" placeholder="请填写成绩"></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-select v-model="stu.gender" placeholder="请选择性别">
            <el-option label="女生" value="1"></el-option>
            <el-option label="男生" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">提交修改</el-button>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
</template>
<script>
import {stuPut} from '@/api/stu'
export default {
  data() {
    return {
      stu: {
        name:'',
        score:'',
        gender:''
      },
    };
  },
  created () {
    let {query} = this.$route
    this.stu = query
  },
  methods: {
    onSubmit() {
      console.log(this.stu);
      let {_id,name,score,gender} = this.stu
      stuPut(_id,{name,score,gender}).then(res=>{ //发起更新操作
        // console.log(res);
        let {code,msg} = res.data
        if(code==1){
          this.$message({
            type:'success',
            message:msg
          })
          this.$router.back() //返回列表页
        }
      })
    },
  },
};
</script>

<style lang="scss" scoped></style>
